// components/footer/footer.js
var cf = require("../../config.js");
const cf2 = require('../../utils/config2')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    employee_data: {
      type: Object,
      value: {},
      observer: function(newVal, oldVal) {
        this.updateList()
      }
    },
    isDimission:{
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
     txt:''
  },
  /**
   * 组件的方法列表
   */
  methods: {
    updateList(){
      let { txt,employee_data } = this.data;
        if(this.properties.isDimission&&!employee_data.toEmployee){
          txt = '马上重新安排金牌置业顾问'
          this.getConsultant()
        }else{
          txt = '您的对接人已转为'+employee_data.toEmployee.name
          setTimeout(function () {
            wx.redirectTo({
              url:'/pages/mycard/card?eId='+employee_data.toEmployee.id
            })
          }, 2000)
        }
     this.setData({txt});
      
    },
    //分配金牌顾问
    getConsultant: function(){
      let that = this
      wx.request({
        url: `${cf2.default.dataCenter}huiSales/ranking/${this.data.employee_data.dimissionEmployee.projectId}/projectSalesTop`,//`http://10.73.159.79:8097/huiSales/ranking/${data.outerId}/projectSalesTop`,
        data:{},
        header: {
          'content-type': 'application/json',
          'token':wx.getStorageSync('authName')
        },
        success:function(res){
          if(res.data.data){
            wx.request({
              url: `${cf.config.pageDomain}applet/mobile/visitcard/employee/getEmployeeInfo`,
              data:{
                phone:res.data.data.mobilePhone,
                cusmallToken: wx.getStorageSync('cusmallToken')
              },
              header: {
                'content-type': 'application/json'
              },
              success:function(res2){
                  setTimeout(function () {
                    wx.redirectTo({
                      url:'/pages/mycard/card?eId='+res2.data.model.employee.id
                    })
                  }, 2000)
              }
            })
          }else{
            setTimeout(function () {
              wx.redirectTo({
                url:'/pages/load/load'
              })
            }, 2000)
          }
         
        }
      })
    },
  }
})
